<template>
  <div>
    <el-row class="title-bar">
      <span class="title-bar-span">直属下级</span>
    </el-row>
    <el-table v-loading="loading" :data="subList" >
      <el-table-column label="编号" prop="orgId" align="center" width="60"/>
      <el-table-column label="名称" prop="orgName" :show-overflow-tooltip="true" />
      <el-table-column label="创建年份"  prop="createYear" width="80" />
      <el-table-column label="级别 " prop="labRankOpt" :formatter="labRankOptFormat" :show-overflow-tooltip="true" />
      <el-table-column label="类型 "  prop="labTypeOpt" :formatter="labTypeOptFormat" width="80"/>
      <el-table-column label="房间"  prop="labNumSum" width="60" align="center"/>
      <el-table-column label="建筑面积"  prop="buildAreaSum" width="80" />
      <el-table-column label="使用面积" prop="usingArea" width="80" />
      <el-table-column label="人员"  prop="employeeNumSum" width="60" align="center"/>
      <el-table-column label="下级"  prop="childNum" width="60" align="center"/>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listSubOrgnization,delOrgnization,listPlatformOrgnization } from "@/api/labdata/orgnization";
export default {
  name: "SubOrgCom",
  data() {
    return {
      currentOrg: {},
      // 遮罩层
      loading: true,

      // 总条数
      total: 0,
      //下级列表
      subList: [],
      // 级别字典
      labRankOptOptions: [],
      // 类型字典
      labTypeOptOptions: [],
      // 状态字典
      orgStatusOptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orgId: null,
      },
      form:{},
      rules:{

      },
    };
  },
  props: {
       childOrg: {type:Object,default:()=>({})},
  },
  watch: {
    childOrg:function(newVal, oldVal){
      this.currentOrg = newVal;
      this.queryParams.orgId = this.currentOrg.orgId;
      this.getList();
    }
  },
  created() {
   this.getDicts("labRankOpt ").then(response => {
     this.labRankOptOptions = response.data;
   });
   this.getDicts("labTypeOpt").then(response => {
     this.labTypeOptOptions = response.data;
   });
   this.getDicts("sys_normal_disable").then(response => {
     this.orgStatusOptOptions = response.data;
   });
    this.currentOrg = this.childOrg;
    this.getList();
  },
  methods: {
    /** 查询实验室工作人员列表 */
    getList() {
      this.loading = true;
      this.queryParams.orgId = this.currentOrg.orgId;
      if(!this.currentOrg.orgFunctionOpt){
        listPlatformOrgnization(this.queryParams).then(response => {
          this.subList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      }else{
        listSubOrgnization(this.queryParams).then(response => {
          this.subList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      }
    },

    //实验室等级
    labRankOptFormat(row, column) {
      return this.selectDictLabel(this.labRankOptOptions, row.labRankOpt);
    },
    //实验室类型
    labTypeOptFormat(row, column) {
      return this.selectDictLabel(this.labTypeOptOptions, row.labTypeOpt);
    },
    //实验室状态
    orgStatusOptFormat(row, column) {
      return this.selectDictLabel(this.orgStatusOptOptions, row.orgStatusOpt);
    },
    handleDelete(row){
      const orgId = row.orgId;
      this.$confirm('是否确认删除编号为"' + orgId + '"的下属数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delOrgnization(orgId);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    }
  }
};
</script>
